import './index.scss'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
import Scroller from 'vux/src/components/scroller/index.vue'
import LoadMore from 'vux/src/components/load-more/index.vue'
export default {
  name: 'userproject',
  components: { Scroller, LoadMore },
  data () {
    return {
      userId: '',
      use_pullup: true,
      pageNo: 1,
      pageSize: 8,
      pullup_con: {
        content: ' ',
        pullUpHeight: 60,
        height: 40,
        autoRefresh: false,
        downContent: ' ',
        upContent: ' ',
        loadingContent: ' ',
        clsPrefix: 'xs-plugin-pullup-'
      },
      tipText: '上拉进行加载',
      show_loading: false,
      list: []
    }
  },
  mounted () {
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path)
    }
    this.userId = window.sessionStorage.getItem('userId')
    this.tipText = '正在加载数据，请稍后'
    this.show_loading = true
    this.goEventList()
  },
  methods: {
    onScrollBottom () {
      console.log('上拉加载')
      this.tipText = '正在加载数据，请稍后'
      this.show_loading = true
      this.pageNo++
      this.goEventList()
    },
    goEventList () {
      http.post(CONSTANT.ONETOONE_DONATE, {userId: this.userId, pageNo: this.pageNo, pageSize: this.pageSize}, (res) => {
        console.log(res)
        if (this.pageNo == 1) {
          if (res.code == 200) {
            if (res.obj == '') {
              this.tipText = '暂时没有一对一捐款记录'
              this.show_loading = false
              return
            }
            for (var i = 0; i < res.obj.length; i++) {
              var names = res.obj[i].name
              if(res.obj[i].biuniqueId != 'eb783144cf9e47f999708a67d48b576d') {
                names = names.split('')  // 将a字符串转换成数组
                names.splice(1, 1, '*') // 将1这个位置的字符，替换成'xxxxx'. 用的是原生js的splice方法。
                names = names.join('')  // 将数组转换成字符串。  完成。
              }
              res.obj[i].name = names
              if (res.obj[i].sex == 'man') {
                res.obj[i].sex = '男'
              } else if (res.obj[i].sex == 'woman') {
                res.obj[i].sex = '女'
              } else {
                res.obj[i].sex = ''
              }
            }
            this.list = res.obj
            this.tipText = '上拉进行加载'
            this.show_loading = false
            this.$nextTick(() => {
              this.$refs.scroller.donePullup(function () {
                this.$refs.scroller.reset()
              })
            })
          }
        } else {
          if (res.code == 200) {
            if (res.obj == '') {
              this.tipText = '没有更多一对一捐助了'
              this.show_loading = false
              this.$nextTick(() => {
                this.$refs.scroller.donePullup(function () {
                  this.$refs.scroller.reset()
                })
              })
              return
            }
            for (var i = 0; i < res.obj.length; i++) {
              if (res.obj[i].sex == 'man') {
                res.obj[i].sex = '男'
              } else if (res.obj[i].sex == 'woman') {
                res.obj[i].sex = '女'
              } else {
                res.obj[i].sex = ''
              }
            }
            this.list = this.list.concat(res.obj)
            this.tipText = '上拉进行加载'
            this.show_loading = false
            this.$nextTick(() => {
              this.$refs.scroller.donePullup(function () {
                this.$refs.scroller.reset()
              })
            })
          }
        }
      })
    },
    goDonateListDetails (id) {
      this.$router.push({path: '/donateListDetails', query: {id: id, hid: this.userId}})
    },
    goHomeDoation (e) {
      // this.$router.push({path: '/homedonation', query: {together_id: e}})
    },
    comeBack () {
      window.history.back()
    }
  }
}
